home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / lib / util / tai_packages.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-03-11  |  5.8 KB  |  266 lines

  1. #include "util.h"
  2. #include "ll_log.h"
  3. #include "cmd.h"
  4.  
  5. extern int errno;               /* put error code into here, like sys call */
  6. extern char *tai_eptr;          /* pointer to error text  */
  7.  
  8. /*      tailor other packages   */
  9.  
  10. tai_pgm (argc, argv, nam, path) /* get name&path of a program */
  11.     int argc;                   /* number of values     */
  12.     char *argv[];               /* list of values       */
  13.     char **nam,                 /* where to put the name of the program */
  14.      **path;                /* where to put path to program */
  15. {
  16.     register int ind;
  17.  
  18.     for (ind = 0; ind < argc; ind++)
  19.     {
  20.     if (lexequ ("=", argv[ind]))
  21.     {                       /* key/value pair       */
  22.         if ((ind += 2) >= argc)
  23.         {
  24.         errno = EFAULT;
  25.         tai_eptr = argv[ind - 1];       /* point to 'key' */
  26.         argv[ind + 1] = 0;
  27.         return (NOTOK);
  28.         }
  29.         if (lexequ ("path", argv[ind - 1]))
  30.         *path = argv[ind];
  31.         else
  32.         if (lexequ ("name", argv[ind - 1]))
  33.         *nam = argv[ind];
  34.         else
  35.         {
  36.         errno = EINVAL;
  37.         tai_eptr = argv[ind - 1];       /* point to 'key' */
  38.         argv[ind + 1] = 0;
  39.         return (NOTOK);
  40.         }
  41.     }
  42.     else
  43.     {                               /* same string for both purposes */
  44.         *path = argv[ind];
  45.         *nam = argv[ind];
  46.     }
  47.     }
  48.     return (YES);
  49. }
  50. /* */
  51.  
  52. #define CMDLHDR     1
  53. #define CMDLLEVEL   2
  54. #define CMDLSIZE    3
  55. #define CMDLSTAT    4
  56. #define CMDLTIMER   5
  57.  
  58. LOCVAR Cmd
  59.         cmdlog[] =
  60. {
  61.     "hdr",      CMDLHDR,    1,
  62.     "level",    CMDLLEVEL,  1,
  63.     "size",     CMDLSIZE,   1,
  64.     "stat",     CMDLSTAT,   1,
  65.     "timer",    CMDLTIMER,  1,
  66.     0,          0,          0
  67. };
  68.  
  69. #define CMDLPFAT    1
  70. #define CMDLPTMP    2
  71. #define CMDLPGEN    3
  72. #define CMDLPBST    4
  73. #define CMDLPFST    5
  74. #define CMDLPPTR    6
  75. #define CMDLPBTR    7
  76. #define CMDLPFTR    8
  77.  
  78. LOCVAR Cmd
  79.         cmdlevel[] =
  80. {
  81.     "fat",      CMDLPFAT,   0,
  82.     "tmp",      CMDLPTMP,   0,
  83.     "gen",      CMDLPGEN,   0,
  84.     "bst",      CMDLPBST,   0,
  85.     "fst",      CMDLPFST,   0,
  86.     "ptr",      CMDLPPTR,   0,
  87.     "btr",      CMDLPBTR,   0,
  88.     "ftr",      CMDLPFTR,   0,
  89. #ifdef NVRCOMPIL
  90.     these are commented out in order to save a trivial amount of
  91.     space.  if you really want the synonyms, add them.  (dhc)
  92.     "llogfat",  CMDLPFAT,   0,
  93.     "llogtmp",  CMDLPTMP,   0,
  94.     "lloggen",  CMDLPGEN,   0,
  95.     "llogbst",  CMDLPBST,   0,
  96.     "llogfst",  CMDLPFST,   0,
  97.     "llogptr",  CMDLPPTR,   0,
  98.     "llogbtr",  CMDLPBTR,   0,
  99.     "llogftr",  CMDLPFTR,   0,
  100. #endif
  101.     0,          0,          0
  102. };
  103.  
  104. #define CMDLSCLS    1
  105. #define CMDLSCYC    2
  106. #define CMDLSWAT    3
  107. #define CMDLSSOME   4
  108. #define CMDLSTIMED   5
  109.  
  110. LOCVAR Cmd
  111.         cmdlstat[] =
  112. {
  113.     "close",    CMDLSCLS,   0,
  114.     "wait",     CMDLSWAT,   0,
  115.     "cycle",    CMDLSCYC,   0,
  116.     "some",     CMDLSSOME,  0,
  117.     "timed",    CMDLSTIMED,  0,
  118. #ifdef NVRCOMPIL
  119.     "llogcls",  CMDLSCLS,   0,
  120.     "cls",      CMDLSCLS,   0,
  121.     "wat",      CMDLSWAT,   0,
  122.     "llogwat",  CMDLSWAT,   0,
  123.     "cyc",      CMDLSCYC,   0,
  124.     "llogcyc",  CMDLSCYC,   0,
  125.     "llogsome", CMDLSSOME,  0,
  126. #endif
  127.     0,          0,          0
  128. };
  129.  
  130.  
  131. tai_log (argc, argv, thelog)    /* get ll_log structure values */
  132.     int argc;                   /* number of values     */
  133.     char *argv[];               /* list of values       */
  134.     LLog *thelog;               /* the ll_log struct to modify */
  135. {
  136.     register int ind;
  137.  
  138.     for (ind = 0; ind < argc; ind++)
  139.     {
  140.     if (lexequ ("=", argv[ind]))
  141.     {                       /* key/value pair       */
  142.         ind += 2;
  143.         switch (cmdsrch (argv[ind - 1], argc - ind + 1, cmdlog))
  144.         {
  145.         case CMDLHDR:
  146.             thelog -> ll_hdr = argv[ind];
  147.             break;
  148.  
  149.         case CMDLLEVEL:
  150.             if (isdigit (argv[ind][0]))
  151.             sscanf (argv[ind], "%d", &(thelog -> ll_level));
  152.             else
  153.             switch (cmdsrch (argv[ind], 0, cmdlevel))
  154.             {
  155.                 case CMDLPFAT:
  156.                 thelog -> ll_level = LLOGFAT;
  157.                 break;
  158.  
  159.                 case CMDLPTMP:
  160.                 thelog -> ll_level = LLOGTMP;
  161.                 break;
  162.  
  163.                 case CMDLPGEN:
  164.                 thelog -> ll_level = LLOGGEN;
  165.                 break;
  166.  
  167.                 case CMDLPBST:
  168.                 thelog -> ll_level = LLOGBST;
  169.                 break;
  170.  
  171.                 case CMDLPFST:
  172.                 thelog -> ll_level = LLOGFST;
  173.                 break;
  174.  
  175.                 case CMDLPPTR:
  176.                 thelog -> ll_level = LLOGPTR;
  177.                 break;
  178.  
  179.                 case CMDLPBTR:
  180.                 thelog -> ll_level = LLOGBTR;
  181.                 break;
  182.  
  183.                 case CMDLPFTR:
  184.                 thelog -> ll_level = LLOGFTR;
  185.                 break;
  186.  
  187.                 default:
  188.                 errno = EINVAL;
  189.                 tai_eptr = argv[ind - 1];
  190.                 argv[ind + 1] = 0;
  191.                 return (NOTOK);
  192.             }
  193.             break;
  194.  
  195.         case CMDLSIZE:
  196.             thelog -> ll_msize = atoi (argv[ind]);
  197.             break;
  198.  
  199.         case CMDLSTAT:
  200.             if (isdigit (argv[ind][0]))
  201.                 /* not all stdio's have a test for octal (dhc) */
  202.             sscanf (argv[ind], "%o", &(thelog -> ll_stat));
  203.             else
  204.             switch (cmdsrch (argv[ind], 0, cmdlstat))
  205.             {
  206.                 case CMDLSCLS:
  207.                 thelog -> ll_stat |= LLOGCLS;
  208.                 break;
  209.  
  210.                 case CMDLSWAT:
  211.                 thelog -> ll_stat |= LLOGWAT;
  212.                 break;
  213.  
  214.                 case CMDLSCYC:
  215.                 thelog -> ll_stat |= LLOGCYC;
  216.                 break;
  217.  
  218.                 case CMDLSSOME:
  219.                 thelog -> ll_stat |= LLOGSOME;
  220.                 break;
  221.  
  222.                 case CMDLSTIMED:
  223.                 /* don't OR, this overrides others */
  224.                 thelog -> ll_stat = LLOGTIMED;
  225.                 break;
  226.  
  227.                 default:
  228.                 errno = EINVAL;
  229.                 tai_eptr = argv[ind - 1];
  230.                 argv[ind + 1] = 0;
  231.                 return (NOTOK);
  232.             }
  233.             break;
  234.  
  235.         case CMDLTIMER:
  236.             thelog -> ll_timmax = atoi (argv[ind]);
  237.             break;
  238.  
  239.  
  240.         default:
  241.             errno = EINVAL;
  242.             tai_eptr = argv[ind - 1];   /* point to 'key' */
  243.             argv[ind + 1] = 0;
  244.             return (NOTOK);
  245.         }
  246.     }
  247.     else
  248.     {
  249.         if (ind == 0)
  250.         thelog -> ll_file = argv[ind];
  251.         else
  252.         {
  253.         errno = EINVAL;
  254.         tai_eptr = argv[ind - 1];   /* point to 'key' */
  255.         argv[ind + 1] = 0;
  256.         return (NOTOK);
  257.         }
  258.     }
  259.     }
  260.  
  261. /*****  disabled due to bug in mm_tai.c:tai_llev() that calles this
  262. /*****  function with a garbage log pointer.
  263. /*****    ll_close (thelog);          /* start with a clean slate */
  264.     return (YES);
  265. }
  266.